//package com.yxw.trade.controller;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import com.zzy.user.dao.CommonMapper;
//import com.zzy.user.dao.DeptMapper;
//import com.zzy.user.model.Dept;
//import com.zzy.user.model.DeptCombotree;
//import com.zzy.user.model.DeptExample;
//import com.zzy.user.model.DeptExample.Criteria;
//import com.zzy.util.dao.Page;
//
//@Controller
//@RequestMapping("/user")
//public class DeptController {
//
//	private static final Logger logger = LoggerFactory
//			.getLogger(DeptController.class);
//
//	@Autowired
//	public DeptMapper deptMapper;
//
//	@Autowired
//	public CommonMapper commonMapper;
//
//	@RequestMapping("/listDeptView.do")
//	public String listDeptView() {
//		return "user/listDept";
//	}
//
//	@RequestMapping("/listDept.do")
//	public @ResponseBody
//	Map<String, Object> listDept(String name) {
//		Map<String, Object> map = new HashMap<String, Object>();
//		DeptExample example = new DeptExample();
//		Criteria criteria = example.createCriteria();
//		if (name != null && !"".equals(name.trim())) {
//			criteria.andNameLike("%" + name.trim() + "%");
//		}
//		List<Dept> list = deptMapper.selectByExample(example);
//		List<DeptCombotree> deptCombotreeList = new ArrayList<DeptCombotree>();
//		List<DeptCombotree> deptCombotreeResult = new ArrayList<DeptCombotree>();
//		if (list != null && list.size() > 0) {
//			Map<Integer, DeptCombotree> deptCombotreeIdMap = new HashMap<Integer, DeptCombotree>();
//			for (Dept dept : list) {
//				DeptCombotree deptCombotree = new DeptCombotree();
//				deptCombotree.setCode(dept.getCode());
//				deptCombotree.setId(dept.getId());
//				deptCombotree.setLevel(dept.getLevel());
//				deptCombotree.setName(dept.getName());
//				deptCombotree.setParentId(dept.getParentId());
//				deptCombotree.setText(dept.getName());
//				deptCombotreeIdMap.put(deptCombotree.getId(), deptCombotree);
//				deptCombotreeList.add(deptCombotree);
//			}
//			for (DeptCombotree deptCombotree : deptCombotreeList) {
//				Integer parentId = deptCombotree.getParentId();
//				if (deptCombotreeIdMap.containsKey(parentId)) {
//					DeptCombotree temp = deptCombotreeIdMap.get(parentId);
//					temp.getChildren().add(deptCombotree);
//				} else {
//					deptCombotreeResult.add(deptCombotree);
//				}
//			}
//		}
//		map.put("rows", deptCombotreeResult);
//		return map;
//	}
//
//	@RequestMapping("/listAllDept.do")
//	public @ResponseBody
//	List<Dept> listAllDept(String name) {
//		Map<String, Object> map = new HashMap<String, Object>();
//		DeptExample example = new DeptExample();
//		Criteria criteria = example.createCriteria();
//		if (name != null && !"".equals(name)) {
//			criteria.andNameLike("%" + name + "%");
//		}
//
//		int total = deptMapper.countByExample(example);
//		map.put("total", total);
//		List<Dept> list = deptMapper.selectByExample(example);
//		return list;
//	}
//
//	@RequestMapping("/addDeptView.do")
//	public String addDeptView() {
//		return "user/addDept";
//	}
//
//
//
//	@RequestMapping("/updateDeptView.do")
//	public String updateDeptView(Model model, Integer id) {
//		Dept Dept = deptMapper.selectByPrimaryKey(id);
//		model.addAttribute("Dept", Dept);
//		return "user/updateDept";
//	}
//
//	/** 递归dept **/
//	public void getDeptIdList(DeptCombotree deptCombotree,
//			List<Integer> deptIdList) {
//		deptIdList.add(deptCombotree.getId());
//		List<DeptCombotree> children = deptCombotree.getChildren();
//		if (children.size() == 0) {
//			return;
//		} else {
//			for (DeptCombotree deptCombotree2 : children) {
//				getDeptIdList(deptCombotree2, deptIdList);
//			}
//		}
//	}
//
//}
